package org.yxing.palpalgps.activity;

import org.yxing.palpalgps.AbstractActivity;
import org.yxing.palpalgps.ActionBar;
import org.yxing.palpalgps.ActionBar.OnActionBarListener;
import org.yxing.palpalgps.R;
import org.yxing.palpalgps.adapter.PhotoAdapter;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

public class UserPhotoGridActivity extends AbstractActivity implements OnActionBarListener, OnItemClickListener {
    
    private String fuid;
    private GridView mGridView;
    private PhotoAdapter mPhotoAdapter;
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photo_grid);
        setTitle(getString(R.string.photos_grid));
        
        fuid = getIntent().getStringExtra("fuid");
        
        mGridView = (GridView) findViewById(R.id.gridView);
        mGridView.setOnItemClickListener(this);
        
        mPhotoAdapter = new PhotoAdapter(this, fuid);
        mGridView.setAdapter(mPhotoAdapter);
        mPhotoAdapter.loadData();
        
        addActionBarItem(ActionBar.Type.Refresh);
        getActionBar().setOnActionBarListener(this);
    }

    public void onActionBarItemClick(int position) {
        switch (position) {
        case 0:
            //重新载入照片列表
            mPhotoAdapter.loadData();
            break;
        }
    }

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = new Intent(this, UserPhotoViewActivity.class);
        intent.putStringArrayListExtra("data", mPhotoAdapter.getItems());
        intent.putExtra("id", (int)id);
        startActivity(intent);
    }
}
